<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/jqueryForm/jquery.form.js"></script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="travelCommend"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <select name="type" class="form-control" >
                    <option value="-1">全部</option>
                    <option value="1">每周推荐</option>
                    <option value="2">每月推荐</option>
                    <option value="3">推荐攻略</option>
                </select>
                <input type="submit" value="查询">
            </form>
            <script>
                $("#searchForm select[name='type']").val(${qo.type});
            </script>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间安排</th>
                    <th>推荐类型</th>
                    <th></th>
                </tr>


            <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td><img src="${entity.coverUrl!}" width="30px"> </td>
                       <td>${entity.title!}</td>
                       <td>${entity.subTitle!}</td>
                       <td>${(entity.schedule?string("yyyy-MM-dd"))!}</td>
                       <td>${entity.typeName}</td>
                        <td>
                            <button class="inputBtn"  data-json='${entity.json}'>修改</button>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<div class="modal fade" id="strategyModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增游记推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden"  name="id">
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >封面：</label>
                        <div class="col-sm-6">
                            <img  id="coverImg"  width="100%" >
                            <input type="hidden" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" readonly onclick="WdatePicker();" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" >推荐类型：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>

                </form>
                <form id="fileForm" action="/images/xx.do" method="post" enctype="multipart/form-data"/>
                    <input id="fileBtn" type="file" class="form-control" name="file" style="display: none" accept="image/*" >
                </form>
                <div style="text-align: center">
                  <a id="releaseList" >点击查看游记文章明细</a>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>



<script>
    $(function () {



        //点击图片
        $("#coverImg").click(function () {
            $("#fileBtn").click();
        })


        //文件按钮改变事件
        $("#fileBtn").change(function () {
            if ($(this).val()) {
                $("#fileForm").ajaxSubmit(function (data) {
                    if (data.url) {
                        $("#coverImg").prop("src",data.url)
                    }
                })
            }
        })

        $(".inputBtn").click(function () {
           var json =$(this).data("json");
            console.log(json);
            $("#editForm input[name='id']").val(json.id);
            $("#editForm input[name='title']").val(json.title);
            $("#editForm input[name='subTitle']").val(json.subTitle);
            $("#editForm select[name='type']").val(json.type);
            $("#editForm input[name='schedule']").val(json.schedule);
            $("#coverImg").prop("src",json.coverUrl);
            $("#releaseList").attr("href","/travel/releaseList.do?travelId="+json.travel.id);

            $("#strategyModal").modal("show")
        })

        //保存
        $(".submitBtn").click(function () {
            var src= $("#coverImg").attr("src");
            $("#editForm input[name='coverUrl']").val(src);
            $("#editForm").ajaxSubmit(function (data) {
                if (data.success) {
                    reload();
                }

            })
        })
    })
</script>


</body>
</html>